<template>
  <t-dialog v-if="isDialog" :header="`${header} 审批、评审记录`" :visible.sync="visible" :onClose="closeDialog"
    :closeOnOverlayClick="false" :confirmBtn="null" width="80%" top="5%">
    <div style="height: 65vh">
      <t-tabs v-model="tabValue">
        <t-tab-panel value="1" label="审批记录">
          <t-table rowKey="id" :data="data" :columns="columns" hover :loading="dataLoading">
            <template #approveType="{ row }">
              {{ row.approveType | filterByDict(dict.type.kpzh_review_type) }}
            </template>
            <template #approveStatus="{ row }">
              <t-tag v-if="row.approveStatus" :theme="handleTheme(row.approveStatus, dict.type.approve_status)"
                variant="light">
                {{ row.approveStatus | filterByDict(dict.type.approve_status) }}
              </t-tag>
              <t-tag v-else theme="warning" variant="light">待审批
              </t-tag>
            </template>
          </t-table>
        </t-tab-panel>
        <!--      <t-tab-panel v-if="standardCategory!=='3'" value="2" label="汇总意见记录" >-->
        <!--        <t-table-->
        <!--          rowKey="index"-->
        <!--          :data="data2"-->
        <!--          :columns="columns2"-->
        <!--        >-->
        <!--          <template  #dealOpinion="{ row }">-->
        <!--            <t-tag :theme="handleTheme(row.dealOpinion,dict.type.deal_opinion)" variant="light" v-if="row.dealOpinion">-->
        <!--              {{row.dealOpinion | filterByDict(dict.type.deal_opinion)}}-->
        <!--            </t-tag>-->
        <!--            <div v-else>-->
        <!--              - -->
        <!--            </div>-->
        <!--          </template>-->
        <!--          <template  #note="{ row }">-->
        <!--            <div v-if="row.note">{{row.note}}</div>-->
        <!--            <div v-else>-</div>-->
        <!--          </template>-->
        <!--          <template  #summary="{ row }">-->
        <!--            <t-tag v-if="row.summary==='1'" theme="success"  variant="light">已汇总</t-tag>-->
        <!--            <t-tag v-else theme="default"  variant="light">未汇总</t-tag>-->
        <!--          </template>-->
        <!--        </t-table>-->
        <!--      </t-tab-panel>-->
        <!--      <t-tab-panel v-if="standardCategory==='6'" value="3" label="评定审批记录" >-->
        <!--        <t-alert style="margin-bottom: 10px" theme="info" v-if="reviewGroupRecord?.content" :title="`${site_tag==='jtt'?'科教处':'科信部'}意见`" :message="reviewGroupRecord?.content">-->
        <!--        </t-alert>-->
        <!--        <t-alert v-else theme="info" style="margin-bottom: 10px"  :title="`${site_tag==='jtt'?'科教处':'科信部'}意见`" message="未提交" >-->
        <!--        </t-alert>-->
        <!--        <t-alert style="margin-bottom: 10px" theme="info" v-if="psYjsFilesNow.length>0" title="专家组评审意见表" >-->
        <!--          <template #message>-->
        <!--            <a  class="t-button-link" target="_blank"  :href="psYjsFilesNow[0].url" >-->
        <!--              {{psYjsFilesNow[0].name}}-->
        <!--            </a>-->
        <!--          </template>-->
        <!--        </t-alert>-->
        <!--        <t-alert v-else theme="info" style="margin-bottom: 10px"  title="专家组评审意见表" message="未提交" >-->
        <!--        </t-alert>-->
        <!--        <t-table-->
        <!--          rowKey="id"-->
        <!--          :data="data4"-->
        <!--          :columns="columns3"-->
        <!--          hover-->
        <!--        >-->
        <!--          <template #sysAttMainEntities="{row}">-->
        <!--            <a class="t-button-link" v-for="(item,index) in row.sysAttMainEntities" :key="index" target="_blank" :href="item.fullFilePath">-->
        <!--              {{item.fileName}}-->
        <!--            </a>-->
        <!--          </template>-->
        <!--          <template #id="{ rowIndex }">-->
        <!--            {{rowIndex+1}}-->
        <!--          </template>-->
        <!--          <template #reviewStatus="{row}">-->
        <!--            <t-tag theme="success" variant="light" v-if="row.reviewStatus==='1'">-->
        <!--              已提交-->
        <!--            </t-tag>-->
        <!--            <t-tag  v-else-if="row.reviewStatus === '0'" theme="warning" variant="light">暂存</t-tag>-->
        <!--            <t-tag theme="danger" variant="light" v-else>-->
        <!--              未提交-->
        <!--            </t-tag>-->
        <!--          </template>-->
        <!--          <template #[`experts.sysUser.duty`]="{ row }">-->
        <!--            <div v-if="['99999',''].includes(row.experts.sysUser?.profTit)">-->
        <!--              {{ row.experts.sysUser?.duty }}-->
        <!--            </div>-->
        <!--            <div v-else>-->
        <!--              {{ row.experts.sysUser?.duty }}/{{ row.experts.sysUser?.profTit | filterByDict(dict.type.prof_tit) }}-->
        <!--            </div>-->
        <!--          </template>-->
        <!--          <template #op="{ row }">-->
        <!--            <t-button v-if="row.projectApproval==='1'"-->
        <!--                      variant="text" class="t-button-link" @click="dialog.reviewType=row.reviewType;dialog.teamId=row.teamId;dialog.objId=row.id;dialog.open=true">-->
        <!--              <t-icon name="info-circle" slot="icon"/>-->
        <!--              详情-->
        <!--            </t-button>-->
        <!--          </template>-->
        <!--          <template #projectApproval="{row}">-->
        <!--            <t-tag theme="success" variant="light" v-if="row.projectApproval==='1'">-->
        <!--              是-->
        <!--            </t-tag>-->
        <!--            <t-tag theme="danger" variant="light" v-else-if="row.projectApproval==='0'">-->
        <!--              否-->
        <!--            </t-tag>-->
        <!--            <t-tag theme="warning" variant="light" v-else-if="row.projectApproval==='2'">-->
        <!--              需要复议-->
        <!--            </t-tag>-->
        <!--            <t-tag theme="warning" variant="light" v-else>-->
        <!--              未提交-->
        <!--            </t-tag>-->
        <!--          </template>-->
        <!--          <template #[`experts.sysUser.education`]="{ row }">-->
        <!--            {{ row.sysUser?.education | filterByDict(dict.type.education) }}-->
        <!--          </template>-->
        <!--          <template #[`experts.sysUser.degree`]="{ row }">-->
        <!--            {{ row.sysUser?.degree | filterByDict(dict.type.degree) }}-->
        <!--          </template>-->
        <!--        </t-table>-->
        <!--      </t-tab-panel>-->
        <!--      <t-tab-panel v-if="standardCategory!=='3'" value="4" label="报审记录" >-->
        <!--        <t-table-->
        <!--          rowKey="id"-->
        <!--          :data="data3"-->
        <!--          :columns="columns"-->
        <!--          hover-->
        <!--          :loading="dataLoading"-->
        <!--        >-->
        <!--          <template #approveType="{row}">-->
        <!--            {{ row.approveType|filterByDict(dict.type.bzh_approve_type) }}-->
        <!--          </template>-->
        <!--          <template #approveStatus="{row}">-->
        <!--            <t-tag v-if="row.approveStatus"-->
        <!--                    :theme="handleTheme(row.approveStatus, dict.type.approve_status )" variant="light">-->
        <!--              {{ row.approveStatus | filterByDict(dict.type.approve_status ) }}-->
        <!--            </t-tag>-->
        <!--            <t-tag v-else theme="warning" variant="light">待审批-->
        <!--            </t-tag>-->
        <!--          </template>-->
        <!--        </t-table>-->
        <!--      </t-tab-panel>-->
      </t-tabs>
    </div>
  </t-dialog>
  <div v-else>
    <t-tabs v-model="tabValue">
      <t-tab-panel value="1" label="审批记录">
        <t-table rowKey="id" :data="data" :columns="columns" hover :loading="dataLoading">
          <template #approveType="{ row }">
            {{ row.approveType | filterByDict(dict.type.new_bzh_approve_type) }}
          </template>
          <template #approveStatus="{ row }">
            <t-tag v-if="row.approveStatus" :theme="handleTheme(row.approveStatus, dict.type.approve_status)"
              variant="light">
              {{ row.approveStatus | filterByDict(dict.type.approve_status) }}
            </t-tag>
            <t-tag v-else theme="warning" variant="light">待审批
            </t-tag>
          </template>
        </t-table>
      </t-tab-panel>
    </t-tabs>
  </div>
</template>

<script>



export default {
  name: "approve-list",
  dicts: ['approve_type', "subject_classification", "prof_tit", "duty", "recommend_type", "new_bzh_approve_type", "approve_status", "kpzh_review_type"],
  components: {

  },
  props: {
    objId: [String, Number],
    isDialog: {
      type: Boolean,
      default: true
    },
    header: {
      type: String,
      default: ''
    },
    reportTrialId: [String, Number],
    standardCategory: [String, Number],
    system: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      data3: [],
      data2: [],
      tabValue: "1",
      dialog: {
        objId: 0,
        teamId: 0,
        open: false,
        reviewType: null,
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        approveType: '',
        businessName: '',
      },
      visible: true,
      data: [],
      columns: [
        // {
        //   colKey: "businessId",
        //   title: "业务id",
        //   align: "center"
        // },
        {
          colKey: "businessName",
          title: "业务名称",
          align: "center",
          ellipsis: true
        },
        {
          colKey: "approveType",
          title: "审批业务类型",
          align: "center",
          // ellipsis: true
        },
        {
          colKey: "approverName",
          title: "审批人",
          align: "center",
          // ellipsis: true
        },
        {
          colKey: "deptName",
          title: "单位",
          align: "center",
          // ellipsis: true
        },
        {
          colKey: "opinion",
          title: "审批意见",
          align: "center",
          width: 300
          // ellipsis: true
        },
        {
          colKey: "approveStatus",
          title: "审批结果",
          align: "center",
          // ellipsis: true
        },
        {
          colKey: "updateTime",
          title: "审批时间",
          align: "center",
          width: 200
        },
      ],

      dataLoading: false,
      data4: [],
      columns2: [
        {
          colKey: 'chapterNum',
          title: '地方标准章条编号',
          align: "center"

        },
        {
          colKey: 'opinion',
          title: '意见内容',
          align: "center"
        },
        {
          colKey: 'personName',
          title: '提出人',
          align: "center"
        },
        {
          colKey: 'deptName',
          title: '提出单位',
          align: "center"
        },
        {
          colKey: 'summary',
          title: '汇总状态',
          align: "center"
        },
        {
          colKey: 'dealOpinion',
          title: '处理意见',
          align: "center"
        },
        {
          colKey: 'note',
          title: '备注',
          align: "center"
        },
      ],
      columns3: [
        {
          colKey: "id",
          title: "专家序号",
          align: "center",
          width: 100,
        },
        // {
        //   colKey: "experts.sysUser.nickName",
        //   title: "专家姓名",
        //   align: "center"
        // },
        // {
        //   colKey: "experts.sysUser.dept.deptName",
        //   title: "所在单位",
        //   align: "center"
        // },
        // {colKey: 'experts.sysUser.duty', title: '职务/职称',align: "center"},
        // // {colKey: 'experts.profTit', title: '职称',align: "center"},
        // {colKey: 'experts.sysUser.majorName', title: '专业',align: "center"},
        // {colKey: 'experts.sysUser.majorNowName', title: '现从事专业',align: "center"},
        // {
        //   colKey: "experts.sysUser.education",
        //   title: "学历",
        //   align: "center",
        //   ellipsis: true
        // },
        // {
        //   colKey: "experts.sysUser.degree",
        //   title: "学位",
        //   align: "center",
        //   ellipsis: true
        // },
        { colKey: 'reviewStatus', title: '评审状态', align: "center", width: 100 },
        { colKey: 'content', title: '评审意见', align: "center", width: 300 },
        { colKey: 'sysAttMainEntities', title: '评审附件', align: "center", width: 120 },
        // {colKey: 'score', title: '评审分数',align: "center"},
        // {colKey: 'projectApproval', title: '是否通过',align: "center"},
        { colKey: 'projectApproval', title: '是否通过', align: "center", width: 100 },
        // {
        //   colKey: "op",
        //   title: "操作",
        //   align: "center"
        // },
      ],
      reviewGroupRecord: null,
      psYjsFilesNow: [],
      site_tag: import.meta.env.VITE_SITE_TAG,
      promise: null,
    }
  },
  async created () {
    // this.getLocalStandardList()


    this.promise = this.$api.kpzh

    this.getList();
    this.getKjcReply();
  },
  methods: {
    getKjcReply () {
      if (Number(this.tabValue) > 1) {
        this.promise.review.projectReviewTeamGetByBusinessIdAndReviewType({
          businessId: this.objId,
          reviewType: "1",
        }).then(res => {
          this.reviewGroupRecord = res.data;
        }).catch((e) => {
          this.$message.error(e.toString());
        });
      }
    },
    getLocalStandardList () {
      return this.promise.opinion.localStandardList({ localId: this.objId }).then(res => {
        this.data2 = res.rows
      }).catch(err => {
        this.$message.error(err)
      })
    },
    getList () {
      this.dataLoading = true;
      this.promise.approve.getByBusinessId(this.objId).then(response => {
        this.data = response.data;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading = false;
        this.$message.error(e.toString());
      });
    },
    getReviewList () {
      if (Number(this.tabValue) > 1) {
        this.promise.review.projectExpertsInfoByReviewType({
          localId: this.objId,
          reviewType: "1",
        }).then(response => {
          this.data4 = response.data || [];
          this.psYjsFilesNow = [];
          if (this.data4.length > 0) {
            this.promise.review.getByTeamIdAndBusinessId(this.objId, this.data4[0].teamId).then(res => {
              getFiles(res.data.id).then((res) => {
                const files = {}
                res.data.forEach((item) => {
                  if (!files[item.moduleKey]) {
                    files[item.moduleKey] = []
                  }
                  files[item.moduleKey].push({
                    name: item.fileName,
                    url: item.fullFilePath,
                    id: item.id,
                    filePath: item.filePath
                  })
                })
                this.psYjsFilesNow = files.dgAndYsPsYjs || [];
              }).catch(e => {
                this.$message.error(e.toString())
              })
            }).catch((e) => {
              this.$message.error(e.toString());
            });
          }
        }).catch((e) => {
          this.$message.error(e.toString());
        });
      }
    },
    closeDialog () {
      this.$emit("update:visible", false);
    },
  }
}
</script>

<style lang="less" scoped>
.t-tab-panel {
  padding: 10px;
}
</style>
